package com.itheima.manage.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.commons.vo.backstage.DistributionVo;
import com.itheima.commons.vo.backstage.SummaryVo;
import com.itheima.commons.vo.backstage.UsersVo;
import com.itheima.dubbo.interfaces.UserInfoApi;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 仪表盘控制器
 * @author yaohu
 * @date 2021/12/16
 * @Version 1.0
 * @describe
 */
@RestController
@RequestMapping("/dashboard")
public class DashboardController {
    @Reference
    private UserInfoApi userInfoApi;

    //注册用户分布，行业top、年龄、性别、地区
    @GetMapping("/distribution")
    public ResponseEntity distribution(@RequestParam(value = "sd") Long startTime,
                                       @RequestParam(value = "ed") Long endTime) {
        DistributionVo distributionVo = userInfoApi.distribution(startTime, endTime);
        return ResponseEntity.ok(distributionVo);
    }

    //新增、活跃用户、次日留存率
    @GetMapping("/users")
    public ResponseEntity users(@RequestParam(value = "type") Integer type,
                                @RequestParam(value = "sd") Long startTime,
                                @RequestParam(value = "ed") Long endTime) {
        UsersVo usersVo = userInfoApi.users(type,startTime, endTime);
        return ResponseEntity.ok(usersVo);
    }

    //概要统计信息
    @GetMapping("/summary")
    public ResponseEntity users() {
        SummaryVo summaryVo = userInfoApi.summary();
        return ResponseEntity.ok(summaryVo);
    }
}
